package com.monkeysonnet.b2dFluent;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.World;
import com.badlogic.gdx.physics.box2d.joints.FrictionJoint;
import com.badlogic.gdx.physics.box2d.joints.FrictionJointDef;

public class FrictionJointFactory extends JointFactory<FrictionJointFactory>
{
	private static final FrictionJointDef _initialDef = new FrictionJointDef();
	
	private FrictionJointDef _def;
	
	public FrictionJointFactory()
	{
		this(false);
	}
	
	FrictionJointFactory(boolean managed)
	{
		super(managed);
		_def = new FrictionJointDef();
		setDef(_def);
	}
	
	public FrictionJointFactory localAnchorA(Vector2 v)
	{
		_def.localAnchorA.set(v);
		return this;
	}
	
	public FrictionJointFactory localAnchorB(Vector2 v)
	{
		_def.localAnchorB.set(v);
		return this;
	}
	
	public FrictionJointFactory maxForce(float f)
	{
		_def.maxForce = f;
		return this;
	}
	
	public FrictionJointFactory maxTorque(float t)
	{
		_def.maxTorque = t;
		return this;
	}
	
	public FrictionJoint create(World w)
	{
		return (FrictionJoint)w.createJoint(_def);
	}
	
	void clear()
	{
		super.clear(_initialDef);
		_def.maxForce = _initialDef.maxForce;
		_def.maxTorque = _initialDef.maxTorque;
		_def.localAnchorA.set(_initialDef.localAnchorA);
		_def.localAnchorB.set(_initialDef.localAnchorB);
	}

	@Override
	public void free()
	{
		B2d.free(this);
	}
}
